import os from "os";
import * as address from "address";
import { BrowserWindow, screen } from "electron";

export default [
  {
    channel: "context",
    type: "handle",
    cb: () => {
      console.log("-----> context");
      return {
        ip: address.ip(),
        no: os.hostname(),
        store_id: 2,
        store_name: "成都华润店",
        department_id: "od-e9787e162063446a0ca4168fff3ef9c8",
      };
    },
  },
  {
    channel: "close",
    type: "on",
    cb: (mainWindow: BrowserWindow) => {
      const printWidth = screen.getPrimaryDisplay().workAreaSize.width;
      const printHeight = screen.getPrimaryDisplay().workAreaSize.height;
      mainWindow.setResizable(true);
      mainWindow.setSize(365, 126);
      mainWindow.setPosition(
        Math.floor((printWidth - 365) / 2),
        printHeight - 226
      );
      mainWindow.setResizable(false);
    },
  },
  {
    channel: "open",
    type: "on",
    cb: (mainWindow: BrowserWindow) => {
      // const printWidth = screen.getPrimaryDisplay().workAreaSize.width
      // const printHeight = screen.getPrimaryDisplay().workAreaSize.height
      mainWindow.setResizable(true);
      mainWindow.setSize(1248, 826);
      // mainWindow.setPosition(
      //   Math.floor((printWidth - 1248) / 2),
      //   Math.ceil((printHeight - 826) / 2) + 200
      // )
      mainWindow.center();
      mainWindow.setResizable(false);
    },
  },
  {
    channel: "entry",
    type: "on",
    cb: (mainWindow: BrowserWindow) => {
      const printWidth = screen.getPrimaryDisplay().workAreaSize.width;
      const printHeight = screen.getPrimaryDisplay().workAreaSize.height;
      mainWindow.setResizable(true);
      mainWindow.setSize(536, 182);
      mainWindow.setPosition(
        Math.floor((printWidth - 365) / 2),
        printHeight - 226
      );
      mainWindow.setResizable(false);
    },
  },
];
